@extends('admin.layout.main')
@section('content')
    <div class="main-content-inner">
        <div class="breadcrumbs ace-save-state" id="breadcrumbs">
            <ul class="breadcrumb">
                <li>
                    <i class="ace-icon fa fa-home home-icon"></i>
                    <a href="/admin/index">首页</a>
                </li>

                <li>
                    <a href="/admin/tpl_index">消息模板管理</a>
                </li>
                <li class="active">
                    <a href="/admin/message_create" >添加系统消息</a>
                </li>
            </ul><!-- /.breadcrumb -->

            {{--<div class="nav-search" id="nav-search">--}}
                {{--<form class="form-search">--}}
								{{--<span class="input-icon">--}}
									{{--<input type="text" placeholder="Search ..." class="nav-search-input"--}}
                                           {{--id="nav-search-input" autocomplete="off"/>--}}
									{{--<i class="ace-icon fa fa-search nav-search-icon"></i>--}}
								{{--</span>--}}
                {{--</form>--}}
            {{--</div><!-- /.nav-search -->--}}
        </div>

        <div class="page-content">
            {{--<div class="page-header">--}}
                {{--<h1>--}}
                    {{--Form Elements--}}
                    {{--<small>--}}
                        {{--<i class="ace-icon fa fa-angle-double-right"></i>--}}
                        {{--Common form elements and layouts--}}
                    {{--</small>--}}
                {{--</h1>--}}
            {{--</div><!-- /.page-header -->--}}

            <div class="row">
                <div class="col-xs-12">
                    <!-- PAGE CONTENT BEGINS -->
                    <form class="form-horizontal" role="form" name="linkform" method="post" onsubmit="clearSessionStorage()" action="/admin/message_store">
                       {{csrf_field()}}
                        <div class="form-group">
                            <label class="col-sm-3 control-label no-padding-right" for="form-field-1">消息标题 </label>

                            <div class="col-sm-9">
                                <input type="text" name="title" id="form-field-1" placeholder="填写消息标题"
                                       class="col-xs-10 col-sm-5"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label no-padding-right" for="form-field-select-1"> 类型 </label>

                            <div class="col-sm-9">
                                <select class="col-xs-10 col-sm-5" id="form-field-select-1" name="msg_type">
                                    <option value="1">系统消息</option>
                                </select>

                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label no-padding-right" for="form-field-2"> 消息内容 </label>
                            <div class="col-sm-9">
                                <textarea id="form-field-2" name="content" class="col-xs-10 col-sm-5 autosize-transition"
                                          style="overflow: hidden; overflow-wrap: break-word; resize: horizontal; height: 112px;"></textarea>
                            </div>
                        </div>
                        <div class="space-4"></div>

                        <div class="form-grouop" style="height: 30px">

                            <label class="col-sm-3 control-label no-padding-right" for="form-field-2">发送人员</label>
                            <div class="col-sm-9">
                                <div class="radio col-xs-10 col-sm-5">
                                    <label>
                                        <input name="type" value="1" class="ace" onclick="closeSelectUser()" checked type="radio">
                                        <span class="lbl"> 群发</span>
                                    </label>
                                    <label>
                                        <input name="type" value="0"  onclick="openSelectUser()" class="ace" type="radio">
                                        <span class="lbl"> 单发</span>
                                    </label>
                                </div>
                            </div>

                        </div>
                        <div class="space-4"></div>

                        <div class="form-group" id="useridsgroup" style="display: none;">
                            <label class="col-sm-3 control-label no-padding-right" for="form-field-2">  </label>
                            <div class="col-sm-9">
                                <div class="panel panel-info" style="width: 400px">
                                    <div class="panel-heading">所选用户</div>
                                    <div class="panel-body">
                                        <ul class="list-group" id="userids">

                                        </ul>
                                    </div>
                                </div>

                            </div>
                            <input type="hidden" name="userids" value="">
                        </div>


                        <div class="space-4"></div>

                        <div class="clearfix form-actions">
                            <div class="col-md-offset-3 col-md-9">
                                <button id="submitBtn" class="btn btn-info" type="submit">
                                    <i class="ace-icon fa fa-check bigger-110"></i>
                                    提交
                                </button>

                                &nbsp; &nbsp; &nbsp;
                                <button class="btn" type="reset">
                                    <i class="ace-icon fa fa-undo bigger-110"></i>
                                    重置
                                </button>
                            </div>
                        </div>
                    </form>
                    <!-- PAGE CONTENT ENDS -->
                </div><!-- /.col -->
            </div><!-- /.row -->
        </div><!-- /.page-content -->
    </div>
    <script>
        function openSelectUser()
        {
            layer.open({
                type: 2,
                title:'选择会员',
                area:['800px','600px'],
                btn: [ '确认'],
                yes:function(index,layero){
                    console.log(sessionStorage.select_ids);
                    var select_ids = JSON.parse(sessionStorage.select_ids);
                    var _this = $('#userids');
                    var ids = '';
                    if(Object.keys(select_ids).length > 0){
                        _this.empty();
                        for(var i in select_ids){
                            var str = ' <li class="list-group-item">'+select_ids[i]+' </li>';
                            ids += i+',';
                            _this.append(str)
                        }
                        $('#useridsgroup').show();
                        ids = ids.substring(0,ids.length-1)
                        $('input[name=userids]').val(ids);

                    }else{
                        _this.empty();
                        $('#useridsgroup').hide();
                    }
                    layer.close(index);
                },
                cancel: function(index, layero){
                    layer.close(index);
                    clearSessionStorage();
                },
                content: '{{url("admin/select_user")}}', //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
            });
        }
        
        function closeSelectUser() {
            $('#useridsgroup').hide();
            $('input[name=userids]').val('');
            clearSessionStorage();
        }

        /**
         * 清除相应的sessionStorage
         */
        function clearSessionStorage() {
            sessionStorage.select_ids = '';
        }
    </script>
@endsection